package com.markus.code.动态规划.股票问题;

/**
 * Author:markusZhang
 * Date:Create in 2020/8/20 14:05
 * todo: 买卖股票的最佳时机含手续费
 */
public class LeetCode_714 {
    public int maxProfit(int[] prices, int fee) {
        if (prices == null || prices.length == 0){
            return 0;
        }
        int minPrice = prices[0];
        int maxProfit = 0;
        for (int i=1;i<prices.length;i++){
            if (prices[i]-prices[i-1]<0){
                maxProfit = Math.max(maxProfit,maxProfit+prices[i-1]-minPrice-fee);
                minPrice = prices[i];
            }
            minPrice = Math.min(prices[i],minPrice);
        }
        return maxProfit;
    }

    public static void main(String[] args) {
        int []prices = {1, 3, 2, 8, 4, 9};
        int fee = 2;
        LeetCode_714 demo = new LeetCode_714();
        System.out.println(demo.maxProfit(prices,fee));
    }
}
